/*
 * Copyright 2021 The Chromium Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * The default style sheet used to render elements with a `popover`
 * content attribute (with HTMLPopoverAttribute feature enabled).
 */

@namespace "http://www.w3.org/1999/xhtml";

/* TODO(crbug.com/1428094) This file should be merged into html.css. */

[popover] {
  position: fixed;
  inset: 0;
  width: fit-content;
  height: fit-content;
  margin: auto;
  border: solid;
  padding: 0.25em;
  overflow: auto;
  color: CanvasText;
  background-color: Canvas;
}

/* This ensures that popovers get display:none when they are not open, and we
   need to be careful not to affect `<dialog popover>` when open as a dialog. */
[popover]:not(:popover-open):not(dialog[open]) {
  display:none;
}

/* The UA stylesheet has a rule like dialog{display:none}, so <dialog popover>
   needs this to be visible when it is open as a popover. */
dialog:popover-open {
  display:block;
}

/* Popovers using anchor positioning get their inset and anchor-scroll properties
   reset, to make it easier to position them. */
[anchor]:popover-open {
  inset:auto;
  anchor-scroll: implicit;
}

/* This rule matches popovers (dialog or not) that are currently open as a
   popover. */
[popover]:popover-open:not(dialog), dialog:popover-open:not([open]) {
  overlay: auto !important;
}

[popover]:popover-open::backdrop {
  /* From the (modified) fullscreen spec: https://fullscreen.spec.whatwg.org/#user-agent-level-style-sheet-defaults: */
  position: fixed;
  inset: 0;
  /* Specific to [popover]: */
  pointer-events: none !important;
  background-color: transparent;
  overlay: auto !important;
}
